#include <swilib.h>
#include "uMyDraw.h"

#if NEWSGOLD || X75
  static char screen[SCREENW*SCREENH*4];
  static const int screensize=SCREENW*SCREENH*4-1;
  static const IMGHDR img = {SCREENW,SCREENH,0xA,(char*)screen};
#else
  static short screen[132*176];
  static const int screensize=SCREENW*SCREENH*2;
  static const IMGHDR img = {132,176,8,(char*)screen};
#endif
  
static DRWOBJ drwobj;

#define RGB16(R, G, B) ((B>>3) | ((G>>2) << 5) | ((R>>3) << 11))

void PutPixel(int x, int y, char alpha, char clr){
  if(!x || !y) return;
  if ((x<scr_w)&&(y<scr_h)){
    RotateCoordinates(&x,&y); 
    char colr[4];
    memcpy(colr,GetMyPaletteColor(clr),4);
#if NEWSGOLD || X75
    long xy = ((y*SCREENW)+x)*4;
    if (xy > screensize){return;};
    screen[xy] = colr[2];
    screen[xy+1] = colr[1];
    screen[xy+2] = colr[0];
    screen[xy+3] = alpha;
#else         
    long xy = ((y*SCREENW)+x);
    if (xy > screensize){return;};
    //if (colr[3]<10)
    //   screen[xy]=0xC0;
    //else
    //{
    screen[xy] =  RGB16(colr[0],colr[1],colr[2]);
     //setColor(colr[0],colr[1],colr[2],colr[3],&screen[xy]);
    //}
#endif
  }
}

void RedrawMyDraw(){
  RECT rc;
  StoreXYWHtoRECT(&rc,0,0,SCREENW,SCREENH);
  SetPropTo_Obj5(&drwobj,&rc,0,(IMGHDR*)&img); 
  SetColor(&drwobj,GetPaletteAdrByColorIndex(0),GetPaletteAdrByColorIndex(1));
  DrawObject(&drwobj);
}
